<%--
    Document   : loanapplication
    Created on : Apr 6, 2011, 3:37:32 PM
    Author     : Dine
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="sj" uri="/struts-jquery-tags"%>
<%@ taglib prefix="sjg" uri="/struts-jquery-grid-tags"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<html>
    <head>
        <sj:head jqueryui="true" jquerytheme="south-street" compressed="false"/>
        <jsp:include page="WEB-INF/fragments/globalHead.html"/>
        <!--        <script src="resources/jquery/jquery.metadata.js" type="text/javascript"></script>-->
        <!--        <script src="resources/jquery/jquery.validate.js" type="text/javascript"></script>-->
        <link rel="stylesheet" href="res/css/validationEngine.jquery.css" type="text/css"/>
        <link rel="stylesheet" href="res/css/template.css" type="text/css"/>
        <!--        <script src="../js/jquery-1.6.min.js" type="text/javascript">-->
        <!--        </script>-->
        <script src="res/js/jquery.validationEngine-en.js" type="text/javascript" charset="utf-8">
        </script>
        <script src="res/js/jquery.validationEngine.js" type="text/javascript" charset="utf-8">
        </script>
        <title>Cashmate <s:property value="#session.branch.branchname"/> - Loan Application</title>
        <style type="text/css">
            .autocomplete{
                font-size: 10px;
            }
            div.container {
                background-color: #eee;
                border: 1px solid red;
                margin: 5px;
                padding: 5px;
            }
            div.container ol li {
                list-style-type: disc;
                margin-left: 20px;
            }
            div.container { display: none }
            .container label.error {
                display: inline;
            }
            .tabs{
                font-size: 11px;
            }
            /*            #loan, #borrower, #spouse, #business, #coborrower, #requirements{
                            overflow: auto;
                            height: 320px;
                        }*/
            #FrmGrid_loanappGrid, #FrmGrid_creditinvGrid {
                overflow: auto !important;
                height: 200px !important;
            }

            .inputContainer{
                position:relative; float:left;
            }

            #tablecidoc{
                font-size: 11px;
            }

            #autocompleteappraise{
                width: 100px !important;
            }

        </style> <!--main.jsp css-->
        <script type="text/javascript">
            jQuery(document).ready(function(){
                // binds form submission and fields to the validation engine
                //                jQuery("#loanappform").validationEngine();
                
                //                jQuery("#loanappform").validationEngine('attach', {promptPosition : "bottomLeft"});

                jQuery("#loanappform").validationEngine('attach', {
                    isOverflown: true,
                    overflownDIV: "#applicationoverflow"
                });
                
                jQuery("#creditform").validationEngine('attach', {
                    isOverflown: true,
                    overflownDIV: "#creditoverflow"
                });
                
                jQuery("#appraisalform").validationEngine('attach', {
                    isOverflown: true,
                    overflownDIV: "#approverflow"
                });
            });
            /**
             *
             * @param {jqObject} the field where the validation applies
             * @param {Array[String]} validation rules for this field
             * @param {int} rule index
             * @param {Map} form options
             * @return an error string if validation failed
             */
            function checkHELLO(field, rules, i, options){
                if (field.val() != "HELLO") {
                    // this allows to use i18 for the error msgs
                    return options.allrules.validate2fields.alertText;
                }
            }
            //            alert('is the form valid? '+jQuery('#loanappform').validationEngine('validate'))
            //            alert('is the form valid? '+jQuery('#creditform').validationEngine('validate'))

            function evalCi(){
                var ci = jQuery('#loanappform').validationEngine('validate');
                if(ci==true){
                    alert('is this form valid?'+ci);
                    document.creditform.submit();
                }else{
                    alert('false');
                }
                
            }
            
            function saveLoanApp(){
                document.getElementById("lastatus").value="Saved";
                document.loanapplicationform.submit();
            }
            
            function postLoanApp(){
                document.getElementById("lastatus").value="posted";
                document.loanapplicationform.submit();
            }
            
            function myPopup(a){
                if(a=="loanapplications"){
                    var s = document.getElementById("applicationimage").value;
                    var url="http://localhost:8080/Cashmate/photo.jsp?fn="+s+"&type="+a;
                    var name = "Application"
                    window.open(url,name,"resizable=no,toolbar=no,scrollbars=yes,menubar=no,status=no,directories=no,width="+500+",height="+500+",left="+500+",top="+500+"");
                }
                
                if(a=="creditinvestigations"){
                    var s = document.getElementById("ciimage").value;
                    var name = "CI"
                    var url="http://localhost:8080/Cashmate/photo.jsp?fn="+s+"&type="+a;
                    window.open(url,name,"resizable=no,toolbar=no,scrollbars=yes,menubar=no,status=no,directories=no,width="+500+",height="+500+",left="+500+",top="+500+"");
                }
                
                if(a=="appraisals"){
                    var s = document.getElementById("appraisalimage").value;
                    var url="http://localhost:8080/Cashmate/photo.jsp?fn="+s+"&type="+a;
                    var name = "Appraisal"
                    window.open(url,name,"resizable=no,toolbar=no,scrollbars=yes,menubar=no,status=no,directories=no,width="+500+",height="+500+",left="+500+",top="+500+"");
                }
                    
            }
            
            function evalLoanApp(){
                var la = jQuery('#creditform').validationEngine('validate');
                if(la==true){
                    alert('is this form valid?'+la);
                    document.loanappform.submit();
                }else{
                    alert('false');
                }
            }
            
            $(document).ready(function(e){
                $("#autocomplete").keyup(function(event){
                    if(event.keyCode == 13){
                        $("#go").click();
                    }
                });
                //                $("#loanappform").validate({
                //                    errorLabelContainer: $("#loanappform div.error")
                //                });
                //
                //                var container = $('div.container');
                //                // validate the form when it is submitted
                //                var validator = $("#loanappform").validate({
                //                    errorContainer: container,
                //                    errorLabelContainer: $("ol", container),
                //                    wrapper: 'li',
                //                    meta: "validate"
                //                });
                //
                //                $(".cancel").click(function() {
                //                    validator.resetForm();
                //                });
                
                $('#lastname').bind('focusout keypress',function(e){
                    var code= (e.keyCode ? e.keyCode : e.which);
                                    
                    if((code==13&&e.type =='keypress')||e.type=='focusout'){
                        e = e||window.event;
                        e.stopPropagation();
                        e.preventDefault();
                        var id= this.id;
                        var bcode = "";
                        var firstname= $('#firstname').val();
                        var middlename= $('#middlename').val();
                        var lastname= $('#lastname').val();
                        $.ajax({
                            type:'POST',
                            url:"Cashmate/get-binfoloanapp",
                            data:"bcode="+bcode+"&firstname="+firstname+"&middlename="+middlename+"&lastname="+lastname,
                            success:function(msg,textStatus,xhr){
                                if(msg.indexOf("exist")==-1){
                                    document.getElementById("firstname").style.color = "black";
                                    document.getElementById("middlename").style.color = "black";
                                    document.getElementById("lastname").style.color = "black";
//                                    alert(msg)
                                    var msgarr = msg.split("|");
                                    var codearr = msgarr[0].split(",");
                                    var namearr = msgarr[1].split(",");
                                    var addressarr = msgarr[2].split(",");
                                    var areaarr = msgarr[3].split(":");
                                    
//                                    if(msgarr[4] != "" &  )
                                    var loanarr = msgarr[4].split(",");
                                    var loanverarr = msgarr[5].split(",");
                                    
//                                    latestloaninfo = "loan:"+loanamount+","+term+","+balance+","+releasedate+","+loanno+","+daysleft+","+accountno+","+Integer.toString(latestloan.getLoanid())+"|";
//                                    latestloanverinfo = "loanver:"+loantype+","+loanclass;

                                    var streetaddrarr = addressarr[0].split(":");
                                    var code = codearr[0].split(":");
                                    var fn = namearr[0].split(":");
                                    var loanamount = loanarr[0].split(":");
                                    var loantype = loanverarr[0].split(":");
                                    
                                    $('#streetaddress').focus();
                                    $('#streetaddress').val(streetaddrarr[1]);
                                    $('#barangay').val(addressarr[1]);
                                    $('#cityormunicipality').val(addressarr[2]);
                                    $('#province').val(addressarr[3]);
                                    $('#borid').val(code[1]);
                                    $('#firstname').val(fn[1]);
                                    $('#middlename').val(namearr[1]);
                                    $('#lastname').val(namearr[2]);
                                    $('#selectedArea').val(areaarr[1]);
                                    
                                    $('#prevamt').val(loanamount[1]);
                                    $('#prevterm').val(loanarr[1]);
                                    $('#prevbal').val(loanarr[2]);
                                    $('#prevdate').val(loanarr[3]);
                                    $('#prevloanno').val(loanarr[4]);
                                    $('#prevleft').val(loanarr[5]);
                                    $('#prevacctno').val(loanarr[6]);
                                    $('#prevloanid').val(loanarr[7]);
                                    
                                    $('#prevclass').val(loanverarr[1]);
                                    $('#prevtype').val(loantype[1]);
                                    document.getElementById("notif").style.visibility = "hidden";
                                    //                                        $('#errorinfo').css("display","none");
                                }else{
//                                    document.getElementById("firstname").style.color = "red";
//                                    document.getElementById("middlename").style.color = "red";
//                                    document.getElementById("lastname").style.color = "red";
                                    document.getElementById("notif").style.visibility = "visible";
                                    $('#streetaddress').val("");
                                    $('#barangay').val("");
                                    $('#cityormunicipality').val("");
                                    $('#province').val("");
                                    //                                        if($('#errorinfo').css("display")=="none"){
                                    //                                            $('#errorinfo').append(document.createTextNode("Borrower doesn't exist in this area"))
                                    //                                            $('#errorinfo').css("display","inline");
                                    //                                        }
                                }
                            },error:
                                function(xhr, textStatus, errorThrown){
                                document.getElementById("firstname").style.color = "red";
                                document.getElementById("middlename").style.color = "red";
                                document.getElementById("lastname").style.color = "red";
                                $('#streetaddress').val("");
                                $('#barangay').val("");
                                $('#cityormunicipality').val("");
                                $('#province').val("");
                            }
                        });
                    }
                });
                
                var incdep = 1;
                var incref = 1;
                var incveh = 1;
                var incoth = 1;
                var incloans = 1;
                var incbus = 1;
                var incper = 1;
                var incsav = 1; 
                var incinf = 1;
                var incdoc = 1;
                
                $("#btndependent").click(function() {
                    var tobecloned = document.getElementById("tobecloned");
                    var cloned = tobecloned.cloneNode(true);
                    var i = parseInt(cloned.childNodes[1].textContent);
                    var i2 = i+incdep;
                    cloned.childNodes[1].textContent = i2;
                    document.getElementById("tbldependent").appendChild(cloned);
                    incdep++;
                });
                
                $('#loantype').bind('change',function(e){
                    e = e||window.event;
                    e.stopPropagation();
                    e.preventDefault();
                    var valueof = this.value;

                    if(valueof=="New"){
                        document.getElementById("borname").setAttribute("disabled", "disabled");
                        document.getElementById("borid").setAttribute("disabled", "disabled");
                        document.getElementById("newacctno").setAttribute("disabled", "disabled");
                    }else{
                        document.getElementById("borname").removeAttribute("disabled");
                        document.getElementById("borid").removeAttribute("disabled");
                        document.getElementById("newacctno").removeAttribute("disabled");
                    }
                    
                });

                $("#btnloans").click(function() {
                    var tobecloned = document.getElementById("tobeclonedloan");
                    var cloned = tobecloned.cloneNode(true);
                    var i = parseInt(cloned.childNodes[1].textContent);
                    var i2 = i+incloans;
                    cloned.childNodes[1].textContent = i2;
                    document.getElementById("tblloan").appendChild(cloned);
                    incloans++;
                });

                $("#btnreferences").click(function() {
                    var tobecloned = document.getElementById("tobeclonedreferences");
                    var cloned = tobecloned.cloneNode(true);
                    var i = parseInt(cloned.childNodes[1].textContent);
                    var i2 = i+incref;
                    cloned.childNodes[1].textContent = i2;
                    document.getElementById("tblreferences").appendChild(cloned);
                    incref++;
                });

                $("#btnbus").click(function() {
                    var tobecloned1 = document.getElementById("tobeclonedbus");
                    var tobecloned2 = document.getElementById("tobeclonedaddress");
                    var tobecloned3 = document.getElementById("tobeclonedstability");
                    var cloned1 = tobecloned1.cloneNode(true);
                    var cloned2 = tobecloned2.cloneNode(true);
                    var cloned3 = tobecloned3.cloneNode(true);
                    var i = parseInt(cloned1.childNodes[1].textContent);
                    var i2 = i+incbus;
                    cloned1.childNodes[1].textContent = i2;
                    var i = parseInt(cloned2.childNodes[1].textContent);
                    var i2 = i+incbus;
                    cloned2.childNodes[1].textContent = i2;
                    var i = parseInt(cloned3.childNodes[1].textContent);
                    var i2 = i+incbus;
                    cloned3.childNodes[1].textContent = i2;
                    document.getElementById("tblbus").appendChild(cloned1);
                    document.getElementById("tbladdress").appendChild(cloned2);
                    document.getElementById("tblstability").appendChild(cloned3);
                    incbus++;
                });

                /* CI PART */

                $("#btnvehicle").click(function() {
                    var tobecloned = document.getElementById("tobeclonedvehicle");
                    var cloned = tobecloned.cloneNode(true);
                    var i = parseInt(cloned.childNodes[1].textContent);
                    var i2 = i+incveh;
                    cloned.childNodes[1].textContent = i2;
                    document.getElementById("tblvehicle").appendChild(cloned);
                    incveh++;
                });

                $("#btnother").click(function() {
                    var tobecloned = document.getElementById("tobeclonedother");
                    var cloned = tobecloned.cloneNode(true);
                    var i = parseInt(cloned.childNodes[1].textContent);
                    var i2 = i+incoth;
                    cloned.childNodes[1].textContent = i2;
                    document.getElementById("tblother").appendChild(cloned);
                    incoth++;
                });

                $("#btnpersonal").click(function() {
                    var tobecloned = document.getElementById("tobeclonedpersonal");
                    var cloned = tobecloned.cloneNode(true);
                    var i = parseInt(cloned.childNodes[1].textContent);
                    var i2 = i+incper;
                    cloned.childNodes[1].textContent = i2;
                    document.getElementById("tblpersonal").appendChild(cloned);
                    incper++;
                });

                $("#btnsavings").click(function() {
                    var tobecloned = document.getElementById("tobeclonedsavings");
                    var cloned = tobecloned.cloneNode(true);
                    var i = parseInt(cloned.childNodes[1].textContent);
                    var i2 = i+incsav;
                    cloned.childNodes[1].textContent = i2;
                    document.getElementById("tblsavings").appendChild(cloned);
                    incsav++;
                });

                $("#btninformants").click(function() {
                    var tobecloned = document.getElementById("tobeclonedinformants");
                    var cloned = tobecloned.cloneNode(true);
                    var i = parseInt(cloned.childNodes[1].textContent);
                    var i2 = i+incinf;
                    cloned.childNodes[1].textContent = i2;
                    document.getElementById("tblinformants").appendChild(cloned);
                    incinf++;
                });

                $("#btndocs").click(function() {
                    var tobecloned = document.getElementById("tobecloneddocs");
                    var cloned = tobecloned.cloneNode(true);
                    var i = parseInt(cloned.childNodes[1].textContent);
                    var i2 = i+incdoc;
                    cloned.childNodes[1].textContent = i2;
                    document.getElementById("tbldocs").appendChild(cloned);
                    incdoc++;
                });
                
                //                var incapp = 1;
                $("#btnbusiness").click(function() {
                    var tobecloned1 = document.getElementById("tobeclonedid");
                    var tobecloned2 = document.getElementById("tobeclonedname");
                    var tobecloned3 = document.getElementById("tobeclonedtype");
                    var tobecloned4 = document.getElementById("tobeclonedfloorarea");
                    var tobecloned5 = document.getElementById("tobeclonedlandarea");
                    var tobecloned6 = document.getElementById("tobeclonedbusstability");
                    var tobecloned7 = document.getElementById("tobeclonedbusmodel");
                    var tobecloned8 = document.getElementById("tobeclonedbusmake");
                    var tobecloned9 = document.getElementById("tobeclonedbusland");
                    var tobecloned10 = document.getElementById("tobecloneddas");
                    var tobecloned11 = document.getElementById("tobeclonedphone");
                    var tobecloned12 = document.getElementById("tobeclonedladd");
                    var tobecloned13 = document.getElementById("tobeclonedrental");
                    var tobecloned14 = document.getElementById("tobeclonedlname");
                    var cloned1 = tobecloned1.cloneNode(true);
                    var cloned2 = tobecloned2.cloneNode(true);
                    var cloned3 = tobecloned3.cloneNode(true);
                    var cloned4 = tobecloned4.cloneNode(true);
                    var cloned5 = tobecloned5.cloneNode(true);
                    var cloned6 = tobecloned6.cloneNode(true);
                    var cloned7 = tobecloned7.cloneNode(true);
                    var cloned8 = tobecloned8.cloneNode(true);
                    var cloned9 = tobecloned9.cloneNode(true);
                    var cloned10 = tobecloned10.cloneNode(true);
                    var cloned11= tobecloned11.cloneNode(true);
                    var cloned12 = tobecloned12.cloneNode(true);
                    var cloned13 = tobecloned13.cloneNode(true);
                    var cloned14 = tobecloned14.cloneNode(true);
                    var i = cloned1.childNodes[0].value = "";
                    document.getElementById("trid").appendChild(cloned1);
                    document.getElementById("trname").appendChild(cloned2);
                    document.getElementById("trtype").appendChild(cloned3);
                    document.getElementById("trfloorarea").appendChild(cloned4);
                    document.getElementById("trlandarea").appendChild(cloned5);
                    document.getElementById("trbusstability").appendChild(cloned6);
                    document.getElementById("trbusmodel").appendChild(cloned7);
                    document.getElementById("trbusmake").appendChild(cloned8);
                    document.getElementById("trbusland").appendChild(cloned9);
                    document.getElementById("trdas").appendChild(cloned10);
                    document.getElementById("trphone").appendChild(cloned11);
                    document.getElementById("trladd").appendChild(cloned12);
                    document.getElementById("trrental").appendChild(cloned13);
                    document.getElementById("trlname").appendChild(cloned14);
                    
                    //                    var i = parseInt(cloned12.childNodes[0].textContent);
                    //                    var i2 = i+incapp;
                    //                    cloned12.childNodes[0].textContent = i2;
                    //                    document.getElementById("trlabelapp").appendChild(cloned12);
                    //                    incapp++;
                });

                /* CI PART */

                /* APPR PART*/
                var incapp = 1;
                $("#btnappraisal").click(function() {
                    var tobecloned1 = document.getElementById("tobeclonedmakeandtype");
                    var tobecloned2 = document.getElementById("tobeclonedbrand");
                    var tobecloned3 = document.getElementById("tobeclonedserial");
                    var tobecloned4 = document.getElementById("tobeclonedmodel");
                    var tobecloned5 = document.getElementById("tobeclonedreg");
                    var tobecloned6 = document.getElementById("tobeclonedmotor");
                    var tobecloned7 = document.getElementById("tobeclonedchasis");
                    var tobecloned8 = document.getElementById("tobeclonedplate");
                    var tobecloned9 = document.getElementById("tobeclonedfair");
                    var tobecloned10 = document.getElementById("tobeclonedlocation");
                    var tobecloned11 = document.getElementById("tobeclonedgen");
                    var tobecloned12 = document.getElementById("tobeclonedapp");
                    var cloned1 = tobecloned1.cloneNode(true);
                    var cloned2 = tobecloned2.cloneNode(true);
                    var cloned3 = tobecloned3.cloneNode(true);
                    var cloned4 = tobecloned4.cloneNode(true);
                    var cloned5 = tobecloned5.cloneNode(true);
                    var cloned6 = tobecloned6.cloneNode(true);
                    var cloned7 = tobecloned7.cloneNode(true);
                    var cloned8 = tobecloned8.cloneNode(true);
                    var cloned9 = tobecloned9.cloneNode(true);
                    var cloned10 = tobecloned10.cloneNode(true);
                    var cloned11= tobecloned11.cloneNode(true);
                    var cloned12 = tobecloned12.cloneNode(true);
                    document.getElementById("trmakeandtype").appendChild(cloned1);
                    document.getElementById("trbrand").appendChild(cloned2);
                    document.getElementById("trserial").appendChild(cloned3);
                    document.getElementById("trmodel").appendChild(cloned4);
                    document.getElementById("trreg").appendChild(cloned5);
                    document.getElementById("trmotor").appendChild(cloned6);
                    document.getElementById("trchasis").appendChild(cloned7);
                    document.getElementById("trplate").appendChild(cloned8);
                    document.getElementById("trfair").appendChild(cloned9);
                    document.getElementById("trlocation").appendChild(cloned10);
                    document.getElementById("trgen").appendChild(cloned11);
                    
                    var i = parseInt(cloned12.childNodes[0].textContent);
                    var i2 = i+incapp;
                    cloned12.childNodes[0].textContent = i2;
                    document.getElementById("trlabelapp").appendChild(cloned12);
                    incapp++;
                });
                
                /* APPR PART*/
                
                $('.rating').change(function(e){
                    e = e||window.event;
                    e.stopPropagation();
                    e.preventDefault();
                    
                    var e = this.id;
                    //                    alert(e);
                    updateTotal(e);
                    updateSuperTotal();
                    
                })
                
                function updateTotal(categ){
                    var rating = null;
                    var totalrating = null;
                    var ratings = document.getElementsByName("rating");
                    var totalratings = document.getElementsByName("totalrating");
                    for(i = 0; i<ratings.length; i++){
                        if(ratings[i].className == categ){
                            rating = ratings[i];
                            break;
                        }
                    }
                    
                    for(i = 0; i<totalratings.length; i++){
                        if(totalratings[i].id == categ){
                            totalrating = totalratings[i];
                            break;
                        }
                    }
                    
                    //                    totalrating.value="0";
                    var temp = 0;
                    for(var i=0; i<ratings.length; i++){
                        if(ratings[i].id == categ){
                            temp+=parseInt(ratings[i].value);
                        }
                    }
                    
                    totalrating.value=temp;
                    
                    var perfectrating = null;
                    var perfectratings = document.getElementsByName("perfectrating");
                    for(var i = 0; i<perfectratings.length; i++){
                        if(perfectratings[i].id == categ){
                            perfectrating = perfectratings[i];
                            break;
                        }
                    }
                    var perf = parseInt(perfectrating.value);
                    var total = parseInt(totalrating.value);
                    
                    //                    alert("perfect rating:"+perfectrating.value);
                    //                    alert("total rating:"+totalrating.value);
                    
                    var percentages = document.getElementsByName("percent");
                    var percent = null;
                    
                    for(var i = 0; i<percentages.length; i++){
                        if(percentages[i].id == categ){
                            percent = percentages[i];
                            break;
                        }
                    }
                    
                    var percents = document.getElementsByName("percentage");
                    var percentage = null;
                    
                    for(var i = 0; i<percents.length; i++){
                        if(percents[i].id == categ){
                            percentage = percents[i];
                        }
                    }
                    
                    var catpercent = parseInt(percent.value);
                    var percent1 = (total/perf)*catpercent;
                    //                    alert("computer percent:"+percent1);
                    
                    percentage.value=percent1;
                    
                }   
                
                function updateSuperTotal(){
                    var g = document.getElementsByName("percentage");
                    var tem = 0; 
                    for(var i=0;i<g.length;i++){
                        tem+=parseInt(g[i].value);
                    }
                    document.getElementById("total").value=tem;
                }


            })
            
            function load(){
                if(document.getElementById("perfectrating_1")!=null){
                    var x = document.getElementsByName("totalvalue");
                    var perf1 = document.getElementById("perfectrating_1");
                    var temp1 = 0;
                    var perf2 = document.getElementById("perfectrating_2");
                    var temp2 = 0;
                    var perf3 = document.getElementById("perfectrating_3");
                    var temp3 = 0;
                    var perf4 = document.getElementById("perfectrating_4");
                    var temp4 = 0;
                    var perf5 = document.getElementById("perfectrating_5");
                    var temp5 = 0;
                    var perf6 = document.getElementById("perfectrating_6");
                    var temp6 = 0;
                    for(var i = 0 ; i<x.length; i++){
                        if(x[i].getAttribute("class")=="totalvalue1"){
                            temp1+=parseInt(x[i].value);
                        }
                        if(x[i].getAttribute("class")=="totalvalue2"){
                            temp2+=parseInt(x[i].value);
                        }
                        if(x[i].getAttribute("class")=="totalvalue3"){
                            temp3+=parseInt(x[i].value);
                        }
                        if(x[i].getAttribute("class")=="totalvalue4"){
                            temp4+=parseInt(x[i].value);
                        }
                        if(x[i].getAttribute("class")=="totalvalue5"){
                            temp5+=parseInt(x[i].value);
                        }
                        if(x[i].getAttribute("class")=="totalvalue6"){
                            temp6+=parseInt(x[i].value);
                        }
                    }
                    perf1.value = temp1;
                    perf2.value = temp2;
                    perf3.value = temp3;
                    perf4.value = temp4;
                    perf5.value = temp5;
                    perf6.value = temp6;
                    document.getElementById("perfectrating_1").value;
                }
            }
        </script> <!--main.jsp script-->
    </head>
    <body onload="load()">
        <jsp:include page="WEB-INF/fragments/filters.jsp"/>
        <!--        viewing privileges-->
        <s:action name="query-privilege" executeResult="false" var="privilege1v">
            <s:param name="moduleid">18</s:param>
            <s:param name="privilege">v</s:param>
            <s:param name="pagename">loanapplication</s:param>
        </s:action>
        <s:action name="query-privilege" executeResult="false" var="privilege2v">
            <s:param name="moduleid">1</s:param>
            <s:param name="privilege">v</s:param>
            <s:param name="pagename">loanapplication</s:param>
        </s:action>
        <s:action name="query-privilege" executeResult="false" var="privilege3v">
            <s:param name="moduleid">2</s:param>
            <s:param name="privilege">v</s:param>
            <s:param name="pagename">loanapplication</s:param>
        </s:action>
        <s:action name="query-privilege" executeResult="false" var="privilege4v">
            <s:param name="moduleid">3</s:param>
            <s:param name="privilege">v</s:param>
            <s:param name="pagename">loanapplication</s:param>
        </s:action>
        <s:action name="query-privilege" executeResult="false" var="privilege5v">
            <s:param name="moduleid">19</s:param>
            <s:param name="privilege">v</s:param>
            <s:param name="pagename">loanapplication</s:param>
        </s:action>
        <s:action name="query-privilege" executeResult="false" var="privilege6v">
            <s:param name="moduleid">20</s:param>
            <s:param name="privilege">v</s:param>
            <s:param name="pagename">loanapplication</s:param>
        </s:action>
        <!--        creating privileges-->
        <s:action name="query-privilege" executeResult="false" var="privilege1c">
            <s:param name="moduleid">18</s:param>
            <s:param name="privilege">c</s:param>
            <s:param name="pagename">loanapplication</s:param>
        </s:action>
        <s:action name="query-privilege" executeResult="false" var="privilege2c">
            <s:param name="moduleid">1</s:param>
            <s:param name="privilege">c</s:param>
            <s:param name="pagename">loanapplication</s:param>
        </s:action>
        <s:action name="query-privilege" executeResult="false" var="privilege3c">
            <s:param name="moduleid">2</s:param>
            <s:param name="privilege">c</s:param>
            <s:param name="pagename">loanapplication</s:param>
        </s:action>
        <s:action name="query-privilege" executeResult="false" var="privilege4c">
            <s:param name="moduleid">3</s:param>
            <s:param name="privilege">c</s:param>
            <s:param name="pagename">loanapplication</s:param>
        </s:action>
        <s:action name="query-privilege" executeResult="false" var="privilege5c">
            <s:param name="moduleid">19</s:param>
            <s:param name="privilege">c</s:param>
            <s:param name="pagename">loanapplication</s:param>
        </s:action>
        <s:action name="query-privilege" executeResult="false" var="privilege6c">
            <s:param name="moduleid">20</s:param>
            <s:param name="privilege">c</s:param>
            <s:param name="pagename">loanapplication</s:param>
        </s:action>
        <s:action name="query-privilege" executeResult="false" var="privilege1e">
            <s:param name="moduleid">18</s:param>
            <s:param name="privilege">e</s:param>
            <s:param name="pagename">loanapplication</s:param>
        </s:action>
        <s:if test="%{#privilege.allowable == false}">
            <script type="text/javascript">window.location="unauthorized.html";</script>
        </s:if>
        <s:else>
            <s:div id="bodyContainer">
                <s:div id="logoContainer" cssClass="ui-widget-content ui-corner-all">
                    <s:include value="WEB-INF/fragments/banner.jsp">
                        <s:param name="branch" value="#session.branch.branchname" />
                    </s:include>
                </s:div>
                <jsp:include page="WEB-INF/fragments/top.jsp"/>
                <jsp:include page="WEB-INF/fragments/mainMenu.jsp?menu=Loan"/>
                <s:if test="#session.branch.branchname=='Head Office'">
                    <jsp:include page="WEB-INF/fragments/left.jsp?type=loan&innerType=loanapplicationho&select1=subMenuLoanApplication&select2=loanApplicationHoSubMenu_${param.cat}"/>
                </s:if>
                <s:if test="#session.branch.branchname!='Head Office'">
                    <jsp:include page="WEB-INF/fragments/left.jsp?type=loan&innerType=loanapplication&select1=subMenuLoanApplication&select2=loanApplicationSubMenu_${param.cat}"/> 
                </s:if>

                <s:div id="contentContainer" cssClass="ui-widget-content ui-corner-all">
                    <h1 id="contentHeader" class="ui-state-default ui-corner-all"></h1>
                    <s:div id="theContent">
                        <s:action name="get-areascoll" executeResult="false" var="a"/>
                        <s:action name="get-products" executeResult="false" var="p"/>
                        <s:action name="get-requirements" executeResult="false" var="r"/>
                        <s:action name="get-typeof" executeResult="false" var="t"/>
                        <c:if test="${param.cat == 'loanappli'}">
                            <s:if test="%{#privilege1c.allowable == false}">
                                <script type="text/javascript">window.location="unauthorized.html";</script>
                                <%--<% System.out.println("hello");%>--%>
                            </s:if>
                            <s:else>
                                <%--<% System.out.println("bye");%>--%>
                                <script type="text/javascript">
                                    $('h1#contentHeader').html('<span id="level1">Create Request</span>');
                                </script>
                                <s:action name="get-borrowers" executeResult="false" var="e"/>
                                <jsp:include page="WEB-INF/fragments/loanapplicationcontent.jsp" />
                            </s:else>
                        </c:if>
                        <c:if test="${param.cat == 'appli'}">
                            <s:if test="%{#privilege2c.allowable == false}">
                                <script type="text/javascript">window.location="unauthorized.html";</script>
                            </s:if>
                            <s:else>
                                <script type="text/javascript">
                                    $('h1#contentHeader').html('<span id="level1">Application Form</span>');
                                </script>
                                <s:action name="get-la-af" executeResult="false" var="laaf"/>
                                <jsp:include page="WEB-INF/fragments/applicationcontent.jsp" />
                            </s:else>
                        </c:if>
                        <c:if test="${param.cat == 'credit'}">
                            <s:if test="%{#privilege3c.allowable == false}">
                                <script type="text/javascript">window.location="unauthorized.html";</script>
                            </s:if>
                            <s:else>
                                <script type="text/javascript">
                                    $('h1#contentHeader').html('<span id="level1">Credit Investigation</span>');
                                </script>
                                <s:action name="get-la-ci" executeResult="false" var="laci"/>
                                <jsp:include page="WEB-INF/fragments/creditinvcontent.jsp" />
                            </s:else>

                        </c:if>
                        <c:if test="${param.cat == 'appraise'}">
                            <s:if test="%{#privilege4c.allowable == false}">
                                <script type="text/javascript">window.location="unauthorized.html";</script>
                            </s:if>
                            <s:else>
                                <script type="text/javascript">
                                    $('h1#contentHeader').html('<span id="level1">Appraisal Report</span>');
                                </script>
                                <s:action name="get-la-ap" executeResult="false" var="laap"/>
                                <jsp:include page="WEB-INF/fragments/appraisalcontent.jsp" />
                            </s:else>

                        </c:if>
                        <c:if test="${param.cat == 'matrix'}">
                            <s:if test="%{#privilege5c.allowable == false}">
                                <script type="text/javascript">window.location="unauthorized.html";</script>
                            </s:if>
                            <s:else>
                                <script type="text/javascript">
                                    $('h1#contentHeader').html('<span id="level1">Credit Matrix</span>');
                                </script>
                                <s:action name="get-la-cm" executeResult="false" var="lacm"/>
                                <jsp:include page="WEB-INF/fragments/creditmatrixcontent.jsp" />
                            </s:else>

                        </c:if>
                        <%--<c:if test="${param.cat == 'gridappl'}">
                            <s:if test="%{#privilege1v.allowable == false}">
                                <script type="text/javascript">window.location="home.jsp";</script>
                            </s:if>
                            <s:else>
                                <script type="text/javascript">
                                    $('h1#contentHeader').html('<span id="level1">Saved Loan Applications</span>');
                                </script>
                                <jsp:include page="WEB-INF/fragments/admin/loanapplication.jsp" />
                            </s:else>
                        </c:if>
                        <c:if test="${param.cat == 'gridcred'}">
                            <s:if test="%{#privilege2v.allowable == false}">
                                <script type="text/javascript">window.location="home.jsp";</script>
                            </s:if>
                            <s:else>
                                <script type="text/javascript">
                                    $('h1#contentHeader').html('<span id="level1">Saved CIs</span>');
                                </script>
                                <jsp:include page="WEB-INF/fragments/admin/creditinvestigation.jsp" />
                            </s:else>
                        </c:if>
                        <c:if test="${param.cat == 'gridappr'}">
                            <s:if test="%{#privilege3v.allowable == false}">
                                <script type="text/javascript">window.location="home.jsp";</script>
                            </s:if>
                            <s:else>
                                <script type="text/javascript">
                                    $('h1#contentHeader').html('<span id="level1">Saved Appraisals</span>');
                                </script>
                                <jsp:include page="WEB-INF/fragments/admin/appraisal.jsp" />
                            </s:else>
                        </c:if>
                        --%>
                        <%--<c:if test="${param.cat == 'gridloanapplisaved'}">
                            <s:if test="%{#privilege6v.allowable == false}">
                                <script type="text/javascript">window.location="home.jsp";</script>
                            </s:if>
                            <s:else>
                                <script type="text/javascript">
                                    $('h1#contentHeader').html('<span id="level1">Saved Loan Applications</span>');
                                </script>
                                <s:action name="grid-loanappli-saved" executeResult="true"/>
                                <jsp:include page="WEB-INF/fragments/admin/loanapp.jsp?cat=saved" />
                            </s:else>
                        </c:if>--%>
                        <c:if test="${param.cat == 'gridloanappliposted'}">
                            <s:if test="%{#privilege6v.allowable == false}">
                                <script type="text/javascript">window.location="unauthorized.html";</script>
                            </s:if>
                            <s:else>
                                <script type="text/javascript">
                                    $('h1#contentHeader').html('<span id="level1">All Loan Applications</span>');
                                </script>
                                <jsp:include page="WEB-INF/fragments/admin/loanapp.jsp?cat=posted" />
                            </s:else>
                        </c:if>
                    </s:div> 
                </s:div>
                <jsp:include page="WEB-INF/fragments/bottom.jsp"/>
            </s:div>
        </s:else>

        <s:set name="stat" value="actionstatus"/>
        <s:if test="%{#stat!=null}">
            <input id="actionstatustext" value="<s:property value="#stat"/>"></input>
            <script>
                var a = document.getElementById("actionstatustext").value;
                alert(a);
                //                history.go(-1);
            </script>
        </s:if>
    </body>
</html>
